import { Modal, Button, Input } from 'antd';

import React from 'react';
import { connect } from 'dva';
const { TextArea } = Input;
const creator = (type, payload) => ({ type, payload });
class EditModal extends React.Component {
  showModal = () => {
    this.setState({
      visible: true,
    });
  };

  handleOk = e => {
    this.props.toggle();

    const _id = this.props._id;
    this.props
      .dispatch(
        creator('paragraph/editParagraphs', {
          _id,
          content: JSON.stringify(eval(this.props.value)),
        }),
      )
      .then(res => {
        if (res.httpStatus === 200) {
          this.props.dispatch(creator('paragraph/getParagraphs'));
        }
      });
  };

  handleCancel = e => {
    console.log(e);
    this.setState({
      visible: false,
    });
  };
  onChange = e => {
    this.props.setValue(e.target.value);
  };
  render() {
    return (
      <div>
        <Modal
          title="修改段落内容"
          visible={this.props.visible}
          onOk={this.handleOk}
          onCancel={this.props.toggle}
        >
          <TextArea rows={8} value={this.props.value} onChange={this.onChange} />
        </Modal>
      </div>
    );
  }
}

// export default EditModal;

export default connect(({ paragraph }) => ({ paragraph }))(EditModal);
